home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Controls
/
Visual Basic Controls.iso
/
vbcontrol
/
ecltray
/
traydemo.frm
< prev
next >
Wrap
Text File
|
1998-04-21
|
9KB
|
251 lines
VERSION 5.00
Object = "{E39DB312-D923-11D1-B45E-0020AF33A8E7}#1.0#0"; "ECLTRAY.OCX"
Begin VB.Form Form1
Caption = "Demo using ECLTray Control"
ClientHeight = 1356
ClientLeft = 48
ClientTop = 336
ClientWidth = 5100
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
ScaleHeight = 1356
ScaleWidth = 5100
ShowInTaskbar = 0 'False
StartUpPosition = 2 'CenterScreen
Begin ECLTrayIcon.Ecltray Ecltray1
Left = 96
Top = 1248
_ExtentX = 804
_ExtentY = 529
IconToolTip = "ECLIPSE« System Tray Icon"
End
Begin VB.CommandButton Command4
Caption = "E&xit"
Height = 320
Left = 3504
TabIndex = 4
Top = 850
Width = 1500
End
Begin VB.CommandButton Command3
Caption = "&Cycle Icon"
Height = 320
Left = 1800
TabIndex = 3
Top = 850
Width = 1500
End
Begin VB.CommandButton Command2
Caption = "Hide &Icon"
Height = 320
Left = 100
TabIndex = 2
Top = 850
Width = 1500
End
Begin VB.CommandButton Command1
Caption = "Change &Tip"
Height = 320
Left = 144
TabIndex = 1
Top = 144
Width = 1500
End
Begin VB.TextBox Text1
Height = 300
Left = 1944
MaxLength = 64
TabIndex = 0
Text = "Text1"
Top = 170
Width = 2940
End
Begin VB.Image Image1
Height = 384
Index = 3
Left = 2400
Picture = "TrayDemo.frx":0000
Stretch = -1 'True
ToolTipText = "My Computer"
Top = 1272
Visible = 0 'False
Width = 384
End
Begin VB.Image Image1
Height = 384
Index = 2
Left = 1968
Picture = "TrayDemo.frx":08CA
Stretch = -1 'True
ToolTipText = "The Globe"
Top = 1272
Visible = 0 'False
Width = 384
End
Begin VB.Image Image1
Height = 384
Index = 1
Left = 1416
Picture = "TrayDemo.frx":0BD4
Stretch = -1 'True
ToolTipText = "Windows Explorer"
Top = 1272
Visible = 0 'False
Width = 384
End
Begin VB.Image Image1
Height = 384
Index = 0
Left = 888
Picture = "TrayDemo.frx":149E
Stretch = -1 'True
ToolTipText = "Internet Explorer"
Top = 1272
Visible = 0 'False
Width = 384
End
Begin VB.Menu mnuMenu
Caption = "Menu"
Visible = 0 'False
Begin VB.Menu mnuRestore
Caption = "&Restore"
End
Begin VB.Menu mnuMinimize
Caption = "Mi&nimize"
End
Begin VB.Menu mnuExit
Caption = "E&xit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' This declares should be in a module but I want to keep the code in a single file
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
Dim OldIcon As StdPicture
Dim OldToolTip As String
Dim IconId As Integer
Private Sub Command1_Click()
Ecltray1.IconToolTip = Text1.Text
End Sub
Private Sub Command2_Click()
With Ecltray1
If .ShowIcon Then
Command2.Caption = "Show &Icon"
.ShowIcon = False
Else
Command2.Caption = "Hide &Icon"
.ShowIcon = True
End If
End With
End Sub
Private Sub Command3_Click()
If IconId > 4 Then IconId = 0 'maximum number of Icon that we have
Select Case IconId
Case 0:
Set Ecltray1.TrayIcon = OldIcon 'Control's Stored Icon
Ecltray1.IconToolTip = OldToolTip 'control's stored ToolTip
Text1.Text = OldToolTip
Case 1 To 4:
Set Ecltray1.TrayIcon = Image1(IconId - 1).Picture ' copy the Image stored in Image1 -must be an Icon!
Ecltray1.IconToolTip = Image1(IconId - 1).ToolTipText ' copy the ToolTipText of Image1. This can be set to anything
Text1.Text = Image1(IconId - 1).ToolTipText
End Select
IconId = IconId + 1
End Sub
Private Sub Command4_Click()
mnuExit_Click
End Sub
Private Sub Ecltray1_DblClick(Button As Integer)
If WindowState = 0 Then 'I tried to use 'If Not WindowState' but the Else part wouldn't trigger. I don't know why.
WindowState = vbMinimized ' minimize the form
Else
WindowState = vbNormal ' limit the viewable state to normal
SetForegroundWindow (Me.hwnd) 'Ensure the form is visible and has the focus
End If
End Sub
Private Sub ecltray1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
' Button can be 1(Left); 2(Right) or 4(Middle)
' Shift can be 1(Shiftkey is down), 2(ControlKey is down) and 4 (AltKey is Down)
' Note that value of shift can be one or combination of the three keys.i.e. 6=(Ctrl and Alt keys as pressed)
' The value of X and Y indicates the location of the mouse cursor
If Button = 2 Then ' Execute only when the right Mouse Button is pressed and release
SetForegroundWindow (Me.hwnd) 'Activate form1
PopupMenu mnuMenu, vbPopupMenuRightAlign 'pops up the menu we created 'mnuMenu'
End If
End Sub
Private Sub Form_Load()
Set OldIcon = Ecltray1.TrayIcon 'copy the control's stored Icon & ToolTipText
OldToolTip = Ecltray1.IconToolTip
Text1.Text = OldToolTip
IconId = 1 'set the next icon to be displayed when the Cycle Icon button is pressed
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Set Form1 = Nothing
End Sub
Private Sub Form_Resize()
If WindowState Then
mnuMinimize.Enabled = False
mnuRestore.Enabled = True
Else
mnuMinimize.Enabled = True
mnuRestore.Enabled = False
End If
End Sub
Private Sub mnuExit_Click()
' ***************************************************************
' NOTE: Quiting the program from the system Icon (popupmenu) by
' means of 'Unload Form1' statement will generate an 'Invalid
' Page Fault in Module <unknown>' message. This will happen
' only when you try to exit the program using the System Icon.
' I still don't know why this happen. To work around this
' problem I used an API call to quit the program properly
' 'Postquitmessage (nExitCode as Long)'. There is one problem
' with it, however. if you remove the code 'X = MsgBox...', the
' Exit code will be ignored and the program will continue running.
' So, the MsgBox is necessary to shut the program. Again, I still
' don't know why this happen. Please send me some information if
' you know how to work around these problems, because I'm still
'